import Foundation

protocol LoginUseCase {
    func login(phoneNumber: String, isAgreedToTerms: Bool) async throws -> User
}

class LoginUseCaseImp: LoginUseCase {
    @Inject private var repository: UserRepository
    
    func login(phoneNumber: String, isAgreedToTerms: Bool) async throws -> User {
        guard isAgreedToTerms else {
            throw NSError(domain: "LoginError", code: 401, userInfo: [NSLocalizedDescriptionKey: "请同意服务协议"])
        }
        return try await repository.login(phoneNumber: phoneNumber)
    }
}